@encodable/registry
All-purpose map data structure on steroids.
- Can be used to store state as global, making a true singleton that can be used across packages.
- Can be used locally as well.
- Support asynchronous values.
Install
npm install @encodable/registry global-box
Example usage
Create registries
import { Registry, SyncRegistry, makeSingleton } from '@encodable/registry';
const registry = new Registry<string>();
const globalRegistry = new Registry({ globalId: 'my-global-key' });
const singleton = makeSingleton(() => new Registry({ globalId: 'my-global-key' }));
Registering
registry.registerValue('key', 1);
registry.registerLoader('key', () => 1);
registry.registerLoader('key', () => Promise.resolve(1));
Registry
can support both constant values and sync/async loaders.SyncRegistry
only support constant values and sync loaders.